#!/bin/bash
#
# https://github.com/Aniverse/inexistence
# Author: Aniverse

script_update=2020.03.02
script_version=r10004

################################################################################################ Debug

usage_for_debug() {
    export local_packages=/etc/inexistence/00.Installation
    export s=$local_packages/package/mono/uninstall
    rm -f $s ; nano $s ; bash $s
}

################################################################################################ Get options

unset LogRootPath LogTimes DebLocation SCLocation LOCKLocation OutputLOG

AppName=mono
AppNameLower=mono
Need_SourceCode=no
pm_action=uninstall

function show_usage() { echo "
$AppName $pm_action $script_version ($script_update)
Usage:
      -l        Specifiy LogBase (Not log file)
      -d        Enable debug mode
      --log     Show logfile's content"
exit 1 ; }

OPTS=$(getopt -o v:l:d -al version:,debug,logbase:,log -- "$@")
[ ! $? = 0 ] && show_usage
eval set -- "$OPTS"

while [ -n "$1" ] ; do case "$1" in
    -v | --version      ) version="$2"  ; shift 2 ;;
    -l | --logbase      ) LogTimes="$2" ; shift 2 ;;
    -d | --debug        ) debug=1       ; shift   ;;
         --log          ) show_log=1    ; shift   ;;
    -- ) shift ; break ;;
esac ; done

################################################################################################ Set Variables

if [[ -f /etc/inexistence/00.Installation/function ]]; then
    source /etc/inexistence/00.Installation/function
else
    source <(wget -qO- https://github.com/Aniverse/inexistence/raw/master/00.Installation/function)
fi

set_variables_log_location
check_var_OutputLOG
debug_log_location
cat_outputlog

################################################################################################




function uninstall_mono() {

    echo >> $OutputLOG
    [[ $CODENAME == jessie ]] && dpkg -r libjpeg8 >> $OutputLOG 2>&1
    rm -f /etc/apt/sources.list.d/mono.list
    APT_UPGRADE
    apt-get purge -y mono-complete ca-certificates-mono >> $OutputLOG 2>&1
    apt-get autoremove -y >> $OutputLOG 2>&1

    status_lock=${AppNameLower}-r
    echo "status_lock=$status_lock" > /tmp/Variables
    rm -f /tmp/$status_lock.1.lock /tmp/$status_lock.2.lock
    { which mono > /dev/null || touch /tmp/$status_lock.1.lock ; } && touch /tmp/$status_lock.2.lock
    [[ -f /tmp/$status_lock.1.lock ]] && rm -rf $LOCKLocation/$AppNameLower.lock
    echo >> $OutputLOG

}





echo_task "Uninstalling $AppName ..."
uninstall_mono & spinner $!
check_status $status_lock
